<template>
	<view class="v">当前地址：{{address}}</view>
	<button @click="sendDataToParent">确认地址信息</button>
	<view>	
		<map style="width: 100%; height: 100vh;" :latitude="latitude" :longitude="longitude" :markers="covers"
			@markertap="markertap">
		</map>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				latitude: 30.6666667,
				longitude: 104.0666667,
				address:{},
				covers:[],	
					
			}
		},
		onLoad() {
				
		       let that = this;
			   uni.getLocation({
			   type: 'gcj02',
			   geocode: true, //设置该参数为true可直接获取经纬度及城市信息
			   success: function(res) {
			    console.log(res)
				that.latitude=res.latitude;
				that.longitude=res.longitude;
				let newCover={
					id:1,
					latitude:that.latitude,
					longitude:that.longitude,
					iconPath: '/static/location@3x.png',
					width: 50, // Specify the width here
					    height: 50, // Specify the height here

				}
				that.covers.push(newCover);
				let res1 = uni.request({
					url:'https://apis.map.qq.com/ws/geocoder/v1/?location=' +that.latitude+','+that.longitude+'&key=YURBZ-LTAKZ-O7UXO-ZRIXT-BF5KT-MQFSA&get_poi=1',
					//dataType: 'jsonp',
					method: 'GET',
					
				success:function(res1){
				  if (res1.statusCode === 200 && res1.data.status === 0) {
				            // 从响应中提取地址信息
							
				            let addressData = res1.data.result.address;
				            that.address = addressData;
							
				            console.log('地址信息:', that.address);
								console.log(res)
				          } else {
				            console.error('请求失败:');
				          }
				}
				})
			
				
					
			   },
			   fail: function() {
				 console.log(1111111)
			   }
			  });
		},
		methods: {
			sendDataToParent() {
			    this.$emit('data-from-child', { address: 'value' }); // 发送数据
				  uni.switchTab({
				  					           url: '/pages/booking/booking'
				  					         });
			    }
		}
	}
</script>

<style lang="scss">
.v{
	background-color: azure;
	
}

</style>
